package com.mercycrazy.recruit.controller;

import com.mercycrazy.recruit.service.IAdminService;
import com.mercycrazy.recruit.user.CreateAdmin;
import com.mercycrazy.recruit.user.ResetAdminPwd;
import com.mercycrazy.recruit.vo.PagedGridResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 对 Admin 运营端暴露的微服务的相关接口
 *
 * @author <a href="mailto:1443424326@qq.com">mercycrazy</a>
 * @since 2023-01-17
 */
@RestController
@RequestMapping("/admin-info")
@Slf4j
@Tag(name = "Admin运营端相关接口")
public class AdminInfoController {

    private final IAdminService adminService;

    public AdminInfoController(IAdminService adminService) {
        this.adminService = adminService;
    }

    @Operation(summary = "Admin运营端分配账户",
            description = "Admin运营端分配账户, 需要鉴权", method = "POST")
    @PostMapping("/create-admin")
    public void createAdmin(
            @RequestBody @Valid CreateAdmin createAdmin) {
        adminService.createAdmin(createAdmin);
    }

    @Operation(summary = "分页查询Admin账户列表",
            description = "分页查询Admin账户列表, 从第一页开始, 需要鉴权", method = "GET")
    @GetMapping("/page-list")
    public PagedGridResult adminListPaged(String username,
                                          @RequestParam(defaultValue = "1") Integer page,
                                          @RequestParam(defaultValue = "10") Integer limit) {

        return adminService.adminListPaged(username, page, limit);
    }

    @Operation(summary = "删除管理员账号",
            description = "按照用户名删除管理员账号, 需要鉴权", method = "DELETE")
    @DeleteMapping("/admin")
    public void deleteAdmin(@RequestParam String username) {
        adminService.deleteAdmin(username);
    }

    @Operation(summary = "重置管理员密码",
            description = "重置管理员密码, 需要鉴权", method = "POST")
    @PostMapping("/reset-pwd")
    public void resetPwd(@RequestBody @Valid ResetAdminPwd resetAdminPwd) {
        adminService.resetAdminPwd(resetAdminPwd);
    }
}